package com.etone.smartAudit.controller;

import com.etone.smartAudit.annotation.LoginAdmin;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.dto.DataMetaTask.DataMetaTaskDTO;
import com.etone.smartAudit.dto.dataMeta.DataMetaConfDTO;
import com.etone.smartAudit.enums.CheckState;
import com.etone.smartAudit.service.DataMetaTaskService;
import com.etone.smartAudit.vo.PagerVO;
import com.etone.smartAudit.vo.dataMetaTask.DataMetaTaskConfDetailVO;
import com.etone.smartAudit.vo.dataMetaTask.DataMetaTaskConfListVO;
import com.etone.smartAudit.vo.dataMetaTask.DataMetaTaskDetailVO;
import com.etone.smartAudit.vo.dataMetaTask.DataMetaTaskListVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import java.util.List;

/**
 * @author: sovy
 * @date: 2020/11/23
 * @description:
 */
@RestController
@AllArgsConstructor
@Api(tags = "数据模型数据入库管理", value = "DataMetaTaskController")
public class DataMetaTaskController {

    private DataMetaTaskService dataMetaTaskService;

    @ApiOperation(value = "数据模型入库《完》")
    @PostMapping("/dataMetaTasks")
    public void add(
            @ApiIgnore @LoginAdmin Admin loginAdmin,
            @ApiParam(value = "数据模型导入详情") @RequestBody @Validated DataMetaTaskDTO dataMetaTaskDTO
    ) {
        dataMetaTaskService.add(loginAdmin, dataMetaTaskDTO);
    }

    @ApiOperation(value = "编辑数据模型入库《完》")
    @PutMapping("/dataMetaTasks/{id}")
    public void edit(
            @ApiIgnore @LoginAdmin Admin loginAdmin,
            @ApiParam(value = "id", required = true) @PathVariable Integer id,
            @ApiParam(value = "数据模型导入详情") @RequestBody @Validated DataMetaTaskDTO dataMetaTaskDTO
    ) {
        dataMetaTaskService.edit(loginAdmin, id, dataMetaTaskDTO);
    }

    @ApiOperation(value = "自动入库转为人工入库《完》")
    @PatchMapping("/dataMetaTasks/{id}/auto2Man")
    public void auto2Man(
            @ApiIgnore @LoginAdmin Admin loginAdmin,
            @ApiParam(value = "id", required = true) @PathVariable Integer id) {
        dataMetaTaskService.auto2Man(loginAdmin, id);
    }

    @ApiOperation(value = "数据模型入库列表《完》")
    @GetMapping("/dataMetaTasks")
    public PagerVO<DataMetaTaskListVO> list(
            @ApiIgnore @LoginAdmin Admin admin,
            @ApiParam(value = "是否自动入库") @RequestParam(required = false) Boolean isAuto,
            @ApiParam(value = "任务名称") @RequestParam(required = false) String taskName,
            @ApiParam(value = "创建时间-开始时间") @RequestParam(required = false) Date startCreateTime,
            @ApiParam(value = "创建时间-结束时间") @RequestParam(required = false) Date endCreateTime,
            @ApiParam(value = "状态") @RequestParam(required = false) CheckState state,
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        return dataMetaTaskService.list(admin, isAuto, taskName, startCreateTime, endCreateTime, state, page, pageSize);
    }

    @ApiOperation(value = "数据模型入库详情《完》")
    @GetMapping("/dataMetaTasks/{id}")
    public DataMetaTaskDetailVO detail(
            @ApiParam(value = "id", required = true) @PathVariable Integer id
    ) {
        return dataMetaTaskService.detail(id);
    }

    @ApiOperation(value = "添加自动入库任务")
    @PostMapping("/dataMetaTasks/addDataMetaConf")
    public void addDataMetaConf(
            @ApiParam(value = "数据入库") @RequestBody DataMetaConfDTO dataMetaConfDTO,
            @ApiIgnore @LoginAdmin Admin admin
    ) {
        dataMetaTaskService.addDataMetaConf(dataMetaConfDTO,admin);
    }

    @ApiOperation(value = "自动配置入库控制列表")
    @GetMapping("/dataMetaTasks/dataMetaConf")
    public PagerVO<DataMetaTaskConfListVO> dataMetaConf(
            @ApiParam(value = "当前页") @RequestParam(required = false, defaultValue = "1") int page,
            @ApiParam(value = "每页显示数量") @RequestParam(required = false, defaultValue = "10") int pageSize,
            @ApiParam(value = "状态") @RequestParam(required = false) String onlineState,
            @ApiParam(value = "任务名称") @RequestParam(required = false) String taskName,
            @ApiParam(value = "模型名称") @RequestParam(required = false) String cnTableName,
            @ApiParam(value = "二级分类") @RequestParam(required = false) String level2Ids
    ) {
        return dataMetaTaskService.dataMetaConf(page,pageSize,onlineState,taskName,cnTableName,level2Ids);
    }

    @ApiOperation(value = "自动配置入库详情")
    @GetMapping("/dataMetaTasks/confDetail/{id}")
    public DataMetaTaskConfDetailVO confDetail(
            @ApiParam(value = "id", required = true) @PathVariable Integer id,
            @ApiIgnore @LoginAdmin Admin admin) {
        return dataMetaTaskService.confDetail(id,admin);
    }
}
